package com.itcast.infohide.controller;

import com.itcast.infohide.entity.OperateLogPO;
import com.itcast.infohide.entity.FileVO;
import com.itcast.infohide.entity.User;
import com.itcast.infohide.service.UserService;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import java.util.List;

@RestController
@RequestMapping(value="/user")
@CrossOrigin
public class UserController {

    @Resource
    private UserService userService;

    @GetMapping(name="根据id做查询", value = "/findByPhone")
    public User findByPhone(String id){
        return userService.findById(id);
    }


    @PostMapping(name="注册新用户", value = "/saveUser")
    public ResponseEntity saveUser(@RequestBody User user){

        return userService.saveUser(user);
    }


    @PostMapping(name="登录/注册", value = "/login")
    public ResponseEntity loginVerification(@RequestBody User user) {
        return userService.loginVerification(user);
    }

    @PostMapping(name="嵌入提取操作", value = "/log")
    public String log(@RequestBody OperateLogPO operateLogPO) {
        return userService.log(operateLogPO);
    }

    @GetMapping(name="记录查询接口", value = "/select")
    public List<OperateLogPO> select(@RequestParam Integer isEmbed) {
        return userService.select(isEmbed);
    }

    @PostMapping(value = "/upload")
    public ResponseEntity upload(@RequestParam("file") MultipartFile file) {
        FileVO upload = userService.upload(file);
        return ResponseEntity.ok(upload);
    }

    @PostMapping(value = "/compareImages")
    public String compareImages(@RequestParam("file1") String file1, @RequestParam("file2") String file2) {
        return userService.compare(file1, file2);
    }
}
